<template>
	<view class="order-page">
	 <view class="order-form-container">
      <view class="supplier-form">
        <!-- 供应商编号 -->
        <view class="form-item">
          <view>供应商编号：</view>
          <view>{{ supplier.id || '无' }}</view>
        </view>

        <!-- 供应商名称 -->
        <view class="form-item">
          <view>供应商名称：</view>
          <view>{{ supplier.name || '无' }}</view>
        </view>

        <!-- 联系人 -->
        <view class="form-item">
          <view>联系人：</view>
          <view>{{ supplier.contact || '无' }}</view>
        </view>

        <!-- 手机号码 -->
        <view class="form-item">
          <view>手机号码：</view>
          <view>{{ supplier.mobile || '无' }}</view>
        </view>

        <!-- 联系电话 -->
        <view class="form-item">
          <view>联系电话：</view>
          <view>{{ supplier.telephone || '无' }}</view>
        </view>

        <!-- 电子邮箱 -->
        <view class="form-item">
          <view>电子邮箱：</view>
          <view>{{ supplier.email || '无' }}</view>
        </view>

        <!-- 传真 -->
        <view class="form-item">
          <view>传真：</view>
          <view>{{ supplier.fax || '无' }}</view>
        </view>

        <!-- 备注 -->
        <view class="form-item">
          <view>备注：</view>
          <view>{{ supplier.remark || '无' }}</view>
        </view>

        <!-- 开启状态 -->
        <view class="form-item">
          <view>开启状态：</view>
          <view>{{ formatStatus(supplier.status) }}</view>
        </view>

        <!-- 排序 -->
        <view class="form-item">
          <view>排序：</view>
          <view>{{ supplier.sort || '无' }}</view>
        </view>

        <!-- 纳税人识别号 -->
        <view class="form-item">
          <view>纳税人识别号：</view>
          <view>{{ supplier.taxNo || '无' }}</view>
        </view>

        <!-- 税率 -->
        <view class="form-item">
          <view>税率：</view>
          <view>{{ supplier.taxPercent || '无' }}</view>
        </view>

        <!-- 开户行 -->
        <view class="form-item">
          <view>开户行：</view>
          <view>{{ supplier.bankName || '无' }}</view>
        </view>

        <!-- 开户账号 -->
        <view class="form-item">
          <view>开户账号：</view>
          <view>{{ supplier.bankAccount || '无' }}</view>
        </view>

        <!-- 开户地址 -->
        <view class="form-item">
          <view>开户地址：</view>
          <view>{{ supplier.bankAddress || '无' }}</view>
        </view>

        <!-- 创建时间 -->
        <view class="form-item">
          <view>创建时间：</view>
          <view>{{ formatDate(supplier.createTime) }}</view>
        </view>
      </view>  <!-- 提交按钮 -->
      <view class="form-item">
        <button type="button" @click="submitForm">修改</button>
      </view>
    </view>
  </view>
</template>

<script>
import { getSupplier } from "@/sheep/api/erp/supplier.js";

export default {
  data() {
    return {
      supplierId: "", // 从路由参数获取供应商ID
      supplier: {}, // 用于存储供应商详情
    };
  },

  methods: {
    fetchSupplierDetails() {
      getSupplier(this.supplierId)
        .then((res) => {
          const supplier = res.data;
          this.supplier = supplier;
        })
        .catch(() => {
          uni.showToast({
            title: "获取供应商详情失败",
            icon: "none"
          });
        });
    },

    // 辅助函数：格式化日期
    formatDate(date) {
      if (!date) return "无";
      const d = new Date(date);
      const year = d.getFullYear();
      const month = String(d.getMonth() + 1).padStart(2, "0");
      const day = String(d.getDate()).padStart(2, "0");
      return `${year}-${month}-${day}`;
    },

    // 格式化开启状态
    formatStatus(status) {
      return status === 1 ? "开启" : "关闭";
    },
   submitForm() { 
	  uni.setStorageSync('supplierId', this.supplierId);
	  uni.navigateTo({
		url: "/pages/erp/supplier/edit"
	  });
	},
  },

  onLoad() {
    this.supplierId = uni.getStorageSync("supplierId");
    this.fetchSupplierDetails();
  },
  onShow() {
    this.supplierId = uni.getStorageSync("supplierId");
    this.fetchSupplierDetails();
  },
};
</script>

<style scoped>

</style>